package cn.com.jinhao.provider.business.controller;

import cn.com.jinhao.hotline.commons.controller.BaseController;
import cn.com.jinhao.hotline.commons.util.RestResponse;
import cn.com.jinhao.hotline.commons.vo.BaseRequestVO;
import cn.com.jinhao.hotline.commons.vo.business.finished.FinishedCondition;
import cn.com.jinhao.hotline.commons.vo.business.finished.FinishedRequestVO;
import cn.com.jinhao.provider.business.entity.WorkFinished;
import cn.com.jinhao.provider.business.service.WorkFinishedService;
import io.swagger.annotations.*;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * hotline-spring-cloud
 * <p>Description: </p>
 *
 * @author ShaneMew
 * @version 1.0
 * @date 2020/6/3
 * @since 2020/6/3
 */
@RestController
@RequestMapping(value = "/finished")
@Api(tags = {"办结服务"})
public class WorkFinishedController extends BaseController {
    @Resource
    WorkFinishedService workFinishedService;

    @ApiOperation(value = "新增办结信息")
    @PostMapping
    public RestResponse<String> add(@ApiParam(name = "finishedRequestVO", value = "办结信息入参类")@Validated(BaseRequestVO.Create.class) @RequestBody FinishedRequestVO finishedRequestVO, BindingResult result) throws Exception {
        validate(result);
        workFinishedService.add(finishedRequestVO);
        return new RestResponse<>(null);
    }

    @ApiOperation(value = "更新办结信息")
    @PutMapping
    public RestResponse<String> update(@ApiParam(name = "finishedRequestVO", value = "办结信息入参类")@Validated(BaseRequestVO.Update.class) @RequestBody FinishedRequestVO finishedRequestVO, BindingResult result) throws Exception {
        validate(result);
        workFinishedService.update(finishedRequestVO);
        return new RestResponse<>(null);
    }

    @ApiOperation(value = "删除办结信息")
    @DeleteMapping
    public RestResponse<String> delete(@ApiParam(name = "id", value = "主键ID")@RequestParam String id) throws Exception {
        workFinishedService.delete(id);
        return new RestResponse<>(null);
    }

    @ApiOperation(value = "办结查询")
    @GetMapping(value = "/selectByCondition")
    public RestResponse<java.util.Map<String, Object>> selectByCondition(@ApiParam(name = "conditions", value = "查询条件")@RequestBody FinishedCondition conditions, BindingResult result) throws Exception{
        validate(result);
        return new RestResponse<>(workFinishedService.selectByCondition(conditions));
    }

    @ApiOperation(value = "通过事件编码和工单编码查询办结详情")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "eventCode", value = "事件编码", required = true),
        @ApiImplicitParam(name = "dispatchCode", value = "工单编码", required = true),
    })
    @GetMapping(value = "/detailByEventCodeAndDispatchCode")
    public RestResponse<WorkFinished> detailByEventCodeAndDispatchCode(@RequestParam String eventCode, @RequestParam String dispatchCode) throws Exception {
        return new RestResponse<>(workFinishedService.detailByEventCodeAndDispatchCode(eventCode,dispatchCode));
    }

    @ApiOperation(value = "通过编码查询办结详情")
    @GetMapping(value = "/detailByCode")
    public RestResponse<WorkFinished> detailByCode(@ApiParam(name = "code", value = "唯一编码", required = true) @RequestParam String code) throws Exception{
        return  new RestResponse<>(workFinishedService.detailByCode(code));
    }
}
